function insertUser(){
	var username = $('#username').val();
	var password = $('#password').val();
	var nickname = $('#nickname').val();
	var email = $('#email').val();
	var mobilePhoneNumber = $('#mobilePhoneNumber').val();
	var gender = $('#gender').val();
	var birthday = $('#birthday').val();
	var user = {};
	user.username = username;
	user.password = password;
	user.nickname = nickname;
	user.email = email;
	user.mobilePhoneNumber = mobilePhoneNumber;
	user.gender = gender == "男" ? 0 : 1; //男：0，女：1
	user.birthday = birthday;
	
	console.log("username = " + username + " , password = " + password);
	
	$.ajax({
		url : "user/insert",
		data : user,
		dataType : "json",
		type : "post",
		error : function(){
			$.messager.alert("提示","服务器出错！");
		},
		success : function(result){
			$('#result').text(result.msg);
		}
	});
}

function deleteUser(){
	var username = $('#username3').val();
	$.ajax({
		url : "user/delete",
		data : {username:username},
		type : "post",
		error : function(){
			$.messager.alert("提示", "删除失败!");
		} ,
		success : function(result){
			$('#result3').text(result.msg);
		}
	});
}

function getUser(){
	var username = $('#username2').val();
	$.ajax({
		url : "user/get",
		data : {username : username},
		type : "post",
		dataType : "json",
		error : function(){
			$.messager.alert("提示","查询失败！");
			$('#tb-update').hide();
		},
		success : function(result){	
			$('#result2').text(JSON.stringify(result));
			//把查询出来的第一条用户数据进行显示并修改
			var user = result.data[0];
			$('#userId').val(user.id);
			$('#username22').val(user.username);
			$('#password22').val(user.password);
			$('#nickname22').val(user.nickname);
			$('#email22').val(user.email);
//			$('#birthday22').val(user.birthday);
			$('#gender22').val(user.gender == 0 ? "男" : "女");
			$('#mobilePhoneNumber22').val(user.mobilePhoneNumber);

			$('#tb-update').show();
		}
	});
}

function updateUser(){
	var id = $('#userId').val();
	var username = $('#username22').val();
	var password = $('#password22').val();
	var nickname = $('#nickname22').val();
	var email = $('#email22').val();
	var mobilePhoneNumber = $('#mobilePhoneNumber22').val();
	var gender = $('#gender22').val();
	var birthday = $('#birthday22').val();
	var user = {};
	user.id = id;
	user.username = username;
	user.password = password;
	user.nickname = nickname;
	user.email = email;
	user.mobilePhoneNumber = mobilePhoneNumber;
	user.gender = gender == "男" ? 0 : 1; //男：0，女：1
	user.birthday = birthday;
	
	console.log("userinfo:" + username);

	$.ajax({
		url: "user/update",
		data: user,
		type:　"post",
		dataType : "json",
		error: function(){
			$.messager.alert("提示", "修改用户信息失败！");
		},
		success: function(result){
			$('#result2').text(result.msg);
		}
	});
}